Skip to content

Preserve constant loop bounds through adjoint-lowering#2959

Merged
paul0403 merged 6 commits into
mainfrom
optimize-adjoint-dyn-loop-bounds
Jul 2, 2026
Merged

Preserve constant loop bounds through adjoint-lowering#2959
paul0403 merged 6 commits into
mainfrom
optimize-adjoint-dyn-loop-bounds

Conversation

@dime10

@dime10 dime10 commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

As laid out in #2936, the --adjoint-lowering pass converts all classical values used by the reverse pass to dynamic ones via a tape caching mechanism (LIFO list.push/pop). This hinders analyzability for example in qp.specs. This PR skips the tape mechanism for constant loop bounds.

As a pre-requisite to implementing the change, the pass is restructured into a more coherent structure (all in the same directory) of pass driver (AdjointLowering.cpp), forward pass / classical value caching (Forward.cpp), reverse pass / inverse quantum instruction stream & adjoint propagation (Reverse.cpp), and a helper data structure (QuantumCache.cpp/hpp). The actual functional change is very small (2f6ad9e).

closes #2936
[sc-122139]

Future improvements: One could apply this fix to any constant classical value cached by the tape.

Additional note: To "fix" the example in the issue one should run the canonicalization pass before the adjoint lowering (standard in our pipeline) so that the detection of constant values is facilitated.

dime10 added 4 commits June 17, 2026 13:33
Relocate the forward pass into the same location as the reverse pass, as
having the two pieces of the pass in different locations is very
confusing. A subdirectory is introduced for the pass for better
organization.
@dime10 dime10 requested a review from a team June 17, 2026 17:44
@codecov

codecov Bot commented Jun 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.97%. Comparing base (8a5fc60) to head (11981dc).
⚠️ Report is 9 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2959      +/-   ##
==========================================
+ Coverage   96.95%   96.97%   +0.02%     
==========================================
  Files         166      166              
  Lines       19143    19209      +66     
  Branches     1772     1788      +16     
==========================================
+ Hits        18560    18628      +68     
+ Misses        430      429       -1     
+ Partials      153      152       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@paul0403 paul0403 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@dime10 dime10 requested a review from a team June 18, 2026 17:48

@joeycarter joeycarter left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just a few editorial things and questions—nothing blocking. 👍

Comment thread doc/releases/changelog-dev.md Outdated
Comment thread mlir/lib/Quantum/Transforms/AdjointLowering/AdjointLowering.cpp Outdated
Comment thread mlir/lib/Quantum/Transforms/AdjointLowering/QuantumCache.cpp Outdated
Comment thread mlir/lib/Quantum/Transforms/AdjointLowering/QuantumCache.hpp Outdated
Comment thread mlir/test/Quantum/AdjointTest.mlir
Comment thread mlir/lib/Quantum/Transforms/AdjointLowering/QuantumCache.cpp
Co-authored-by: Joey Carter <joey.snarrcarter@gmail.com>
@paul0403 paul0403 merged commit 6e9112f into main Jul 2, 2026
40 checks passed
@paul0403 paul0403 deleted the optimize-adjoint-dyn-loop-bounds branch July 2, 2026 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

qp.specs output on for loops is symbolic after running adjoint.lowering

3 participants